/*
 * @(#)Page.java	1.0 2011/05/18
 *
 * Copyright (c) 2011, IBM CRL and/or its affiliates. All rights reserved.
 * IBM PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.hrm.util;


/**
 * @author zhuchaoqiang
 * <b>Summary: </b> 分页工具类 <b>Remarks: </b> 实现了分页逻辑的管理，其他实体类继承此类
 */
public class Page extends MyObject{

	/**
	 * pagesize:TODO（单页记录数）
	 */
	private int pagesize=20;// 单页记录

	/**
	 * currentpage:TODO（当前页面）
	 */
	private int currentpage = 1;// 当前页面

	/**
	 * countdate:TODO（总记录数）
	 */
	private int counts;// 总记录数

	/**
	 * countPage:TODO（总页数）
	 */
	private int countPage;

	
	/** 
	 * current:当前页起始 
	 */
	private int currentStart=1;
	
	private String currPath;
	
	
	public String getCurrPath() {
		return currPath;
	}
	public void setCurrPath(String currPath) {
		this.currPath = currPath;
	}
	/** 
	 * <b>Summary: </b>
	 *     构造一个 Page  
	 * <b>Remarks: </b>
	 *     构造类 Page 的构造函数 Page 
	 */
	public Page() {
		super();
		this.currentpage=1;
	}
	public Page(int currentpage) {
		super();
		this.currentpage=currentpage;
	}
	public int getCurrentpage() {
		return currentpage;
	}	

	public void setCurrentpage(int currentpage) {

		if (currentpage > getCountPage()&&getCountPage()!=0) {
			this.currentpage = getCountPage();
		} else {
			if (currentpage < 1) {
				this.currentpage = 1;
			} else {
				this.currentpage = currentpage;
			}
		}
		this.currentStart=(this.currentpage - 1) * pagesize+1;
		//this.currentEnd=(this.currentpage * pagesize)<counts?(this.currentpage * pagesize):counts;
	}

	public int getCurrentStart() {
		return currentStart;
	}
	
	public int getPagesize() {
		return pagesize;
	}

	public void setPagesize(int pagesize) {
		this.pagesize = pagesize;
	}

	public int getCounts() {
		return counts;
	}

	public void setCounts(int counts) {
		this.counts = counts;
		int i = this.counts / this.pagesize;
		if ((this.counts % this.pagesize) != 0) {
			i += 1;
		}
		this.countPage=i;
	}

	// 由记录数设定有关的页面数。
	public int getCountPage() {
		int i = this.counts / this.pagesize;
		if ((this.counts % this.pagesize) != 0) {
			i += 1;
		}
		this.countPage=i;
		return this.countPage;
	}

	public int getLastPage() {
		return this.getCurrentpage() - 1;
	}

	public int getNextPage() {
		return this.getCurrentpage() + 1;
	}	

	public int getNext() {
		return this.currentpage * pagesize;
	}


	public void setCountPage(int countPage) {
		int i = this.counts / this.pagesize;
		if ((this.counts % this.pagesize) != 0) {
			i += 1;
		}
		this.countPage=i;
		this.countPage = countPage;
	}

	/**
	 * <b>Summary: </b> main(测试该类)
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Page page = new Page();
		page.setCounts(101);
		page.setCurrentpage(2);

	}

}
